<template>
  <div>
    <!-- v-if="isOk" -->
    <!-- tree-props 树形的配置 子节点的判断 -->
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
    >
      <el-table-column prop="id" label="ID"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="primary">正常</el-tag>
          <el-tag v-else type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="del(scope.row.id)"
            type="danger"
            icon="el-icon-delete"
            circle
            size="mini"
          ></el-button>
          <el-button
            @click="edit(scope.row)"
            type="primary"
            icon="el-icon-edit"
            circle
            size="mini"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getRoleList } from "../../http";
export default {
  data() {
    return {
      // isOk: false,
      tableData: [],
    };
  },
  created() {
    this.getTableData();
  },
  methods: {
    // 获取list的数据
    async getTableData() {
      let res = await getRoleList();
      this.tableData = res.list;
    },
    // 删除
    del(id) {
      // console.log(id);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          // 点击确认 准备删除
          let res = await menuDelete(id);
          if (res.code === 200) {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.tableData = res.list;
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 点击编辑按钮 将数据传给父组件 然后在弹窗中显示
    edit(data) {
      this.$emit("edit", data);
    },
  },
};
</script>

<style>
</style>